package com.u.social.recommend.service.articles;

import com.u.social.recommend.model.ArticleDTO;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: u-social
 * @description: 召回策略
 * @author: Alex Wu
 * @createDate: 2025-04-07 11:42
 **/
public class ArticlesRecallService {

    /**
     * 热门召回
     */
    public List<ArticleDTO> hotRecall(Long topK) {
        System.out.println("远程调用热门帖子，召回500条数据");
        List<ArticleDTO> articles = new ArrayList<>();
        for (int i = 0; i < topK; i++) {
            ArticleDTO article = new ArticleDTO();
            article.setId((long) i);
            article.setTitle("Hot Article " + i);
            article.setContent("Content of hot article " + i);
            article.setScore((float) Math.random());
            articles.add(article);
        }
        return articles;
    }

    /**
     * 向量召回
     *
     * @param vector 向量
     * @return 召回的文章列表
     */
    public List<ArticleDTO> embeddingRecall(List<String> vector, Long topK) {
        System.out.println("远程调用向量召回访问Milvus ，召回500条数据");
        List<ArticleDTO> articles = new ArrayList<>();
        for (int i = 0; i < topK; i++) {
            ArticleDTO article = new ArticleDTO();
            article.setId((long) i);
            article.setTitle("Embedding Article " + i);
            article.setContent("Content of embedding article " + i);
            article.setScore((float) Math.random());
            articles.add(article);
        }
        return articles;
    }

    /**
     * 用户行为召回（协同过滤）
     *
     * @param userId 用户ID
     * @return 召回的文章列表
     */
    public List<ArticleDTO> userCFBehaviorRecall(Long userId, Long topK) {
        System.out.println("远程调用用户行为召回，召回500条数据");
        List<ArticleDTO> articles = new ArrayList<>();
        for (int i = 0; i < topK; i++) {
            ArticleDTO article = new ArticleDTO();
            article.setId((long) i);
            article.setTitle("User Behavior Article " + i);
            article.setContent("Content of user behavior article " + i);
            article.setScore((float) Math.random());
            articles.add(article);
        }
        return articles;
    }

    /**
     * 探索召回
     *
     * @param topK 召回的文章数量
     * @return 召回的文章列表
     */
    public List<ArticleDTO> exploreRecall(Long topK) {
        System.out.println("远程调用探索文章召回，召回500条数据");
        List<ArticleDTO> articles = new ArrayList<>();
        for (int i = 0; i < topK; i++) {
            ArticleDTO article = new ArticleDTO();
            article.setId((long) i);
            article.setTitle("Explore Article " + i);
            article.setContent("Content of explore article " + i);
            article.setScore(0.0f);
            articles.add(article);
        }
        return articles;
    }


}
